package com.example.rf.service

import com.example.rf.dao.PostDao
import com.example.rf.entity.Post
import kotlinx.coroutines.reactive.awaitFirst
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
open class PostService {

    @Autowired
    lateinit var postDao: PostDao

    @Autowired
    lateinit var postService: PostService

    @Transactional
    open suspend fun test1(): List<Post> {
        val vo = Post()
        vo.title = "标题1"
        vo.fullTitle = "这是标题1"
        vo.content = "这是内容1"
        val entity = postDao.save(vo).awaitFirst()

        return listOf(entity, postService.test2())
    }

    @Transactional
    open suspend fun test2(): Post {
        val vo = Post()
        vo.title = "标题2"
        vo.fullTitle = "这是标题2"
        vo.content = "这是内容2"
        throw RuntimeException("测试回滚")
//        return postDao.save(vo).awaitFirst()
    }
}